package _thread_lock._concurrency.leakybucket;


import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;

/**
 * @Author: huangya
 * @Date: 2020/11/18
 * @Description:
 */
public class LeakyBucketTest {

    private static LeakyBucket leakyBucket = new LeakyBucket(100, 1);

    public static void main(String[] args) throws InterruptedException {
        ExecutorService executorService = Executors.newCachedThreadPool();
        for(int i=0; i<1000; i++){
            //休眠1秒
            TimeUnit.MINUTES.sleep(1);
            //
            executorService.execute(()->{
                boolean result = leakyBucket.tryAcquire();
                System.out.println(result);
            });
        }
        executorService.shutdown();
    }
}
